package com.example.wanbaqian.utils;

import android.content.Context;
import android.database.Cursor;
import android.support.v7.app.AlertDialog;

import com.example.wanbaqian.base.BaseSQLiteDao;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/5/11 0011.
 */

public class DialogUtils {
    private static DialogInterface mDialogInterface;

    public interface DialogInterface {
        void backValue(String key, String value);
    }

    /**
     * 申请资料的dialog
     *
     * @param title
     * @param type
     * @param context
     * @param dialogInterface
     */
    public static void showSingDialog(String title, String type, Context context, DialogInterface dialogInterface) {
        mDialogInterface = dialogInterface;
        BaseSQLiteDao dao = new BaseSQLiteDao(context);
        Cursor cursor = dao.selectByType(type);
        final List<String> keys = new ArrayList<>();
        final List<String> values = new ArrayList<>();
        keys.clear();
        values.clear();
        while (cursor.moveToNext()) {
            keys.add(cursor.getString(1));
            values.add(cursor.getString(2));
        }
        AlertDialog.Builder builderliving = new AlertDialog.Builder(context);
        builderliving.setTitle(title);
        builderliving.setSingleChoiceItems(cursor, -1, "enum_value", new android.content.DialogInterface.OnClickListener() {
            @Override
            public void onClick(android.content.DialogInterface dialog, int which) {
                mDialogInterface.backValue(keys.get(which), values.get(which));
                dialog.dismiss();
            }
        });
        builderliving.show();
    }
}
